import {Component, OnInit, ViewContainerRef} from '@angular/core';
import {Prohouseid} from "../../../../model/Prohouseid";
import {NzModalRef, NzModalService} from "ng-zorro-antd/modal";
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";
import {CprkeditComponent} from "../cprkedit/cprkedit.component";
import {Kcsl} from "../../../../model/Kcsl";

@Component({
  selector: 'app-cprklist',
  templateUrl: './cprklist.component.html',
  styleUrls: ['./cprklist.component.css']
})
export class CprklistComponent implements OnInit {
  pl:Array<Prohouseid>
  kl:Array<Kcsl>
  constructor(private modal: NzModalService, private viewContainerRef: ViewContainerRef,
              private adminService: AdminService,
              private alertService: AlertService) {
    this.pl = new Array<Prohouseid>()
  }

  ngOnInit(): void {
    this.getProhouseids()
    this.getKcsl()
  }
  getProhouseids(){
    this.adminService.getProhouseids().then((data:any)=>{
      if(data.msg == "ok"){
        this.pl = data.list
      }else{
        this.alertService.showError("获取入库信息失败")
      }
    })
  }
  record(id:string) {
    const modalwindow:NzModalRef = this.modal.create({
      nzTitle: '入库信息编辑',
      nzContent: CprkeditComponent,
      nzViewContainerRef: this.viewContainerRef,
      nzComponentParams: {
        id:id
      },
      nzFooter: [

        {
          label: '确定',
          type: 'primary',
          onClick: () => this.modal.confirm({ nzTitle: '请确认入库数量', nzContent: '入库数量一经确定，无法修改' ,
            nzOnOk: () => new Promise(resolve => {
              let temp = modalwindow.getContentComponent().p;
              if(!temp.rksj){
                this.alertService.showWarning("入库时间必填")
                resolve(false)
              }else{
                modalwindow.getContentComponent().save();
                setTimeout(() => {

                  resolve(true);
                  this.getProhouseids()
                  this.getKcsl()

                  //this.getEmpDetailByEmpid(this.empid);
                  //this.loadEmpImg();
                }, 2000)
              }
            })
          })
        },

        {
          label: '关闭',
          type: 'dashed',
          onClick: () =>modalwindow.destroy()
        }
      ]

    })

  }
  getCuptestlistByClqk(id:string){
    this.adminService.getProhouseidByClqk(id).then((data:any)=>{
      if(data.msg == "ok"){
        this.pl = data.list
      }else{
        this.alertService.showError("根据处理情况查询失败")
      }
    })
  }

  getKcsl(){
    this.adminService.getKcsls().then((data:any)=>{
      if(data.msg == "ok"){
        this.kl = data.list
      }else{
        this.alertService.showError("获取库存数量统计失败")
      }

    })
  }
}
